#!/bin/sh
#
# dkms_autoinstaller - A service to automatically install DKMS modules for new kernels.
#
# chkconfig: 345 04 04
# description: Compiles and install kernel modules automatically for new \
#              kernels at boot.

### BEGIN INIT INFO
# Provides: dkms_autoinstaller dkms
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Short-Description: DKMS kernel modules installer service
# Description: A service to automatically install DKMS modules for new kernels.
### END INIT INFO


exec="@SBINDIR@/dkms"
MODDIR="@MODDIR@"

test -f $exec || exit 0

case "$1" in
    start)
		if [ -n "$2" ]; then
			kernel="$2"
		else
			kernel=$(uname -r)
		fi
		if [ ! -d "$MODDIR/$kernel/build/include" ]; then
			echo "Automatic installation of modules for kernel $kernel was skipped since the kernel headers for this kernel do not seem to be installed."
		else
			dkms autoinstall --kernelver "$kernel"
			res=$?
			test $res = 0
		fi
		;;
	stop|restart|force-reload|status|reload)
		# There is no stop action, this and the 04 priority during stop is
		# added to make RHEL chkconfig happy.
		# Ignore others on debian/ubuntu too
        ;;
    *)
        echo "Usage: $0 {start}"
        exit 2
esac
